﻿@using Microsoft.AspNetCore.Components.Forms

<EditForm Model="@student" OnValidSubmit="HandleValidSubmit">
    <DataAnnotationsValidator />
    <InputText @bind-Value="@student.Code" />
    <ValidationMessage For="()=>student.Code" />


    <InputText @bind-Value="@student.Name" />
    <ValidationMessage For="()=>student.Name" />

    <button type="submit">submit</button>
</EditForm>


@code {
    @using System.ComponentModel.DataAnnotations;

    private Student student = new Student();
    private void HandleValidSubmit()
    {
        // Save the data
    }

    public class Student
    {
        [Required(AllowEmptyStrings = false, ErrorMessage = "必填项!")]
        public string Name { get; set; }

        [StringLength(2, ErrorMessage = "超出规定长度！")]
        public string Code { get; set; }
    }
}
